package BIOtest05;

import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.UUID;

public class ServerSocketThread extends Thread{
    private Socket socket;
    public ServerSocketThread(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        //先读取传递过来的数据
        try {
            DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
            String s = dataInputStream.readUTF();
            System.out.println("读取到的后缀："+s);
            OutputStream outputStream = new FileOutputStream("C:/Intel/"+ UUID.randomUUID()+s);
            byte[] bytes = new byte[1024];
            int len;
            while ((len = dataInputStream.read(bytes))!=-1){
                outputStream.write(bytes,0,len);
            }
            outputStream.flush();
            System.out.println("服务的接收文件保存成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
